$(function() {
	platformId = "";// 当前页面所使用的平台id
	getPlatformId();// 
	//数据初始值
	getTAXLocalStorageInit();
	//监听数据变化，存储本地数据
	addListenerEventFun();
	addNumberKeyboard();
});

function getPlatformId() {// 从测试序列界面的链接路径中截取ID
	var url = location.search; // 获取url中"?"符后的字串
	path = location.host;
	if (url.indexOf("?") != -1) {
		var str = url.substr(1);
		strs = str.split("&");
		platformId = strs[3].split("=")[1];
	}
}

tests=function(moudle){ // TAX页面数据发送功能
 	var inputs=$("#top input");//拿到所有的输入框
 	var selects=$("#top select");//拿到所有的下拉框
	if(moudle=="start"){//点击的是开始和终止按钮
		console.log("开始测试");
		var str=getDate(inputs,selects);
		ajaxSendTAXSignal(str,1);
	}
	else if(moudle=="stop"){
		console.log("停止测试");
		var str=getDate(inputs,selects);
		ajaxSendTAXSignal(str,3);
	}
	else if(moudle=="updated"){
		console.log("更新数据");
		var str=getDate(inputs,selects);
		console.log(str);
		ajaxSendTAXSignal(str,2);
	}	
 };
 
 function getDate(inputs,selects){
		var str='{';
		for(var i=0;i<inputs.length;i++){//获取Input的键值
	    	var input = $(inputs[i]);
	    	var key =input.attr("name");
	   		var value =input.val();
	    	str += key+':"'+value+'",';
	    }
	    for(var i=0;i<selects.length;i++){//获取select的键值
	    	var select = $(selects[i]);
	    	var key =select.attr("name");
	   		var value =select.find("option:selected").attr("value"); 
	   		if(selects.length-1==i){
				str += key+':"'+value+'"}';
	    	}else{
	    		str += key+':"'+value+'",';
	    	}
	    }
	    return str;
	}
 
 function ajaxSendTAXSignal(str,sendSignal){
	 addLoading();
	 $.ajax({
			"url" : "../../../tax/ajaxSendTAXSignal",
			"type" : "post",
			"data" : {
				"sendSignal" : sendSignal,
				"platformId" : platformId,
				"str" : str
			},
			"success" : function(result) {
				removeLoading();
				if (result.flag == 0) {
					var taxBean = result.content;//返回的对象
					beanToStr(taxBean);
					console.log("发送成功");
					book('发送成功');
				} else {
					var content=result.errorInfo;
					book(content);
				}
			},
			"error" : function() {
				removeLoading();
				var content="手工测试连接错误！";
				book(content);
			}
		});
 }
 
 function beanToStr(taxBean){
	 var str="";
	 if(taxBean.time!=null){
		 $("#time").text(taxBean.time);
	 }
	 if(taxBean.perHour!=null){
		 $("#perHour").text(taxBean.perHour);
	 }
	 if(taxBean.theSpeedLimit!=null){
		 $("#theSpeedLimit").text(taxBean.theSpeedLimit);
	 }
	 if(taxBean.distance!=null){
		 $("#distance").text(taxBean.distance);
	 }
	 if(taxBean.theCumulativeFigures!=null){
		 $("#theCumulativeFigures").text(taxBean.theCumulativeFigures);
	 }
	 if(taxBean.theMileage!=null){
		 $("#theMileage").text(taxBean.theMileage);	
	 }
	 if(taxBean.worksLineNumber!=null){
		 $("#worksLineNumber").text(taxBean.worksLineNumber);
	 }
	 if(taxBean.lineOfWorks!=null){
		 $("#lineOfWorks").text(taxBean.lineOfWorks);
	 }
	 if(taxBean.telesemeType!=null){
		 $("#telesemeType").text(taxBean.telesemeType);
	 }
	 if(taxBean.telesemeNumber!=null){
		 $("#telesemeNumber").text(taxBean.telesemeNumber);
	 }
	 if(taxBean.theLocomotiveSignal!=null){
		 $("#theLocomotiveSignal").text(taxBean.theLocomotiveSignal);
	 }
	 if(taxBean.workingMode!=null){
		 $("#workingMode").text(taxBean.workingMode);
	 }
	 if(taxBean.sideLine!=null){
		 $("#sideLine").text(taxBean.sideLine);
	 }
	 if(taxBean.subdivisionSideLine!=null){
		 $("#subdivisionSideLine").text(taxBean.subdivisionSideLine);
	 }
	 if(taxBean.localBranch!=null){
		 $("#localBranch").text(taxBean.localBranch);
	 }
	 if(taxBean.lowerBranch!=null){
		 $("#lowerBranch").text(taxBean.lowerBranch);
	 }
	 if(taxBean.pressureInformationFirst!=null){
		 $("#pressureInformationFirst").text(taxBean.pressureInformationFirst);
	 }
	 if(str!=""){
		 $(".left").append(str);
	 }
	 var str1 = "";
	 if(taxBean.pressureInformationSecond!=null){
		 $("#pressureInformationSecond").text(taxBean.pressureInformationSecond);
	 }
	 if(taxBean.pressureInformationThree!=null){
		 $("#pressureInformationThree").text(taxBean.pressureInformationThree);	
	 }
	 if(taxBean.pressureInformationFour!=null){
		 $("#pressureInformationFour").text(taxBean.pressureInformationFour);
	 }
	 if(taxBean.woodSpeed!=null){
		 $("#woodSpeed").text(taxBean.woodSpeed);
	 }
	 if(taxBean.wcol!=null){
		 $("#wcol").text(taxBean.wcol);
	 }
	 if(taxBean.dirverNumFir!=null){
		 $("#dirverNumFir").text(taxBean.dirverNumFir);
	 }
	 if(taxBean.dirverNumSec!=null){
		 $("#dirverNumSec").text(taxBean.dirverNumSec);
	 }
	 if(taxBean.brakeType!=null){
		 $("#brakeType").text(taxBean.brakeType);
	 }
	 if(taxBean.trainType!=null){
		 $("#trainType").text(taxBean.trainType);
	 }
	 if(taxBean.identify!=null){
		 $("#identify").text(taxBean.identify);
	 }
	 if(taxBean.carNum!=null){
		 $("#carNum").text(taxBean.carNum);
	 }
	 if(taxBean.totalWeight!=null){
		 $("#totalWeight").text(taxBean.totalWeight);
	 }
	 if(taxBean.totalLength!=null){
		 $("#totalLength").text(taxBean.totalLength);
	 }
	 if(taxBean.numberOfCars!=null){
		 $("#numberOfCars").text(taxBean.numberOfCars);
	 }
	 if(taxBean.speedRating!=null){
		 $("#speedRating").text(taxBean.speedRating);
	 }
	 if(taxBean.fcfx!=null){
		 $("#fcfx").text(taxBean.fcfx);
	 }
	 if(taxBean.runPathNum!=null){
		 $("#runPathNum").text(taxBean.runPathNum);
	 }
	 if(str1!=""){
		 $(".center").append(str1);
	 }
	 
	 
	 var str2 = "";
	 if(taxBean.loadWeight!=null){
		 $("#loadWeight").text(taxBean.loadWeight);
	 }
	 if(taxBean.customerCar!=null){
		 $("#customerCar").text(taxBean.customerCar);
	 }
	 if(taxBean.haveyCar!=null){
		 $("#haveyCar").text(taxBean.haveyCar);
	 }
	 if(taxBean.emptyCar!=null){
		 $("#emptyCar").text(taxBean.emptyCar);
	 }
	 if(taxBean.notUseCar!=null){
		 $("#notUseCar").text(taxBean.notUseCar);
	 }
	 if(taxBean.replaceCar!=null){
		 $("#replaceCar").text(taxBean.replaceCar);
	 }
	 if(taxBean.attachmentBoardNum!=null){
		 $("#attachmentBoardNum").text(taxBean.attachmentBoardNum);
	 }
	 if(taxBean.deviceNum!=null){
		 $("#deviceNum").text(taxBean.deviceNum);
	 }
	 if(taxBean.trainNum!=null){
		 $("#trainNum").text(taxBean.trainNum);
	 }
	 if(taxBean.trainNumName!=null){
		 $("#trainNumName").text(taxBean.trainNumName);
	 }
	 if(taxBean.trainNo!=null){
		 $("#trainNo").text(taxBean.trainNo);
	 }
	 if(taxBean.wheelDiameter1!=null){
		 $("#wheelDiameter1").text(taxBean.wheelDiameter1);
	 }
	 if(taxBean.wheelDiameter2!=null){
		 $("#wheelDiameter2").text(taxBean.wheelDiameter2);
	 }
	 if(taxBean.doubleNeedleTableRange!=null){
		 $("#doubleNeedleTableRange").text(taxBean.doubleNeedleTableRange);
	 }
	 if(taxBean.dieselEnginePulse!=null){
		 $("#dieselEnginePulse").text(taxBean.dieselEnginePulse);
	 }
	 if(taxBean.BDSAndGPSDistance!=null){
		 $("#BDSAndGPSDistance").text(taxBean.BDSAndGPSDistance);
	 }
	 if(taxBean.BTMDistance!=null){
		 $("#BTMDistance").text(taxBean.BTMDistance);
	 }
	 if(str2!=""){
		 $(".right").append(str2);
	 }
 }
 
 function makeStr(key,value){
	 var str='<div><span>'+key+'</span><label>'+value+'</label></div>';
	 return str;
 }
 function addListenerEventFun(){
		//监听数据变化，存储本地数据
		$("input").on('input',function(e)  
		{  
			switch (e.target.name){
				case 'Version':
					localStorage.setItem('TAXVersion', e.target.value);
					break;
				default:
					break;
			}
		}); 
		
		//监听数据变化，存储本地数据
		$("select").on('change',function(e){
			console.log(e);
			switch (e.target.name){
				case 'Producer':
					localStorage.setItem('TAXProducer', e.target.selectedIndex);
					break;
				default:
					break;
			}
		});
	}

//读取存储数据BTM数据
 function getTAXLocalStorageInit(){
 	if(localStorage.getItem('TAXVersion')){
 		$("input[name='Version']").val(localStorage.getItem('TAXVersion'));
 	}
 	
 	if(localStorage.getItem('TAXProducer')){
 		$("select[name = 'Producer']").get(0).selectedIndex = localStorage.getItem('TAXProducer');
 	}
 }
 
//添加数字软键盘
 function addNumberKeyboard(){
	 if($(".numkeyboard").length>0){
			$(".numkeyboard").numkeyboard({
				keyboardRadix: 600, //键盘大小基数
				mainbackground: '#313439', //主背景色
				menubackground: '#313439', //头背景色
				exitbackground: '#4376A0', //关闭按钮背景色
				buttonbackground: 'transparent', //键盘背景色
				clickeve: true, //是否绑定元素click事件
			});
		}
 }